//old version of shuffle 

unsigned char check (unsigned char new_num)
{
	already=0;
	j=0;

	while(cards_played[j]!=0)
	{
		if (new_num==cards_played[j])
		already=1;
	j++;
	}
		if(already==0)
		{
			cards_played[card]=next_card;
		return 1;
	}
		else
			{return 0;}
}


unsigned char shuffle (void)
{
next_card=0;
already=0;
j=0;
i=0;

unsigned char card_new_position[52]={0},new_name[52]={0},new_type[52]={0};

	next_card=RANDOM(1,52);
	next_card=next_card-1;

	while(j<52)
	{
		while(new_name[i]!=0)
		{
			if (next_card==card_new_position[i])
			already=1;
		i++;
		}//end while check
		i=0;
			if(already==0)
			{
				new_name[j]=last_name[next_card];
				new_type[j]=last_type[next_card];

				card_new_position[j]=next_card;
					next_card=RANDOM(1,52);
					next_card=next_card-1;
					j++;
					//return 0;
			}
			else
				{	
				next_card=RANDOM(1,52);
				next_card=next_card-1;
				already=0;
			//	return 0;
				}


	}//end main while
	
	for(i=0;i<52;i++)
	{
	last_name[i]=new_name[i];
	last_type[i]=new_type[i];
	}

for(i=0;i<52;i++)
	{
	new_name[i]=0;
	new_type[i]=0;
	}
	
	return 1;
}



void shuffling()
{
CLEAR_LCD
LCD_XY(2,1)
LCD_TEXT("Shuffling...")
	 do{    //first shuffle
	 finished=shuffle();
	}while(finished!=1);
}
